<template>
  <div class="ma-content-block lg:flex justify-between p-4">
    <!-- CRUD 组件 -->
    <ma-crud :options="options" :columns="columns" ref="crudRef">
      <template #driver_id="{ record }">
        <!-- 对标题加上 tag -->
        <a-tag color="blue">{{ record?.driver?.driver_name }}</a-tag>
      </template>
    </ma-crud>
  </div>
</template>
<script setup>
import { ref, reactive,defineProps } from 'vue'
import predictionDriverCar from '@/api/prediction/predictionDriverCar'
import { Message } from '@arco-design/web-vue'
import tool from '@/utils/tool'
import * as common from '@/utils/common'
const emits = defineEmits(['handlecolse'])
const crudRef = ref()
const props = defineProps({
    id: {
			default: {},
		},
});

const numberOperation = (newValue, id, numberName) => {
  predictionDriverCar.numberOperation({ id, numberName, numberValue: newValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}

const switchStatus = (statusValue, id, statusName) => {
  predictionDriverCar.changeStatus({ id, statusName, statusValue }).then( res => {
    res.success && Message.success(res.message)
  }).catch( e => { console.log(e) } )
}


const options = reactive({
  id: 'flyos_prediction_driver_car',
  rowSelection: {
    showCheckedAll: true
  },
  pk: 'id',
  operationColumn: true,
  operationWidth: 160,
  formOption: {
    viewType: 'modal',
    width: 600
  },
  api: predictionDriverCar.getList,
  recycleApi: predictionDriverCar.getRecycleList,
  add: {
    show: true,
    api: predictionDriverCar.save,
    auth: ['prediction:driverCar:save']
  },
  edit: {
    show: true,
    api: predictionDriverCar.update,
    auth: ['prediction:driverCar:update']
  },
  delete: {
    show: true,
    api: predictionDriverCar.deletes,
    auth: ['prediction:driverCar:delete'],
    realApi: predictionDriverCar.realDeletes,
    realAuth: ['prediction:driverCar:realDeletes']
  },
  recovery: {
    show: true,
    api: predictionDriverCar.recoverys,
    auth: ['prediction:driverCar:recovery']
  },
  import: {
    show: true,
    url: 'prediction/driverCar/import',
    templateUrl: 'prediction/driverCar/downloadTemplate',
    auth: ['prediction:driverCar:import']
  },
  export: {
    show: true,
    url: 'prediction/driverCar/export',
    auth: ['prediction:driverCar:export']
  },
  beforeRequest: (params) => {
    params.driver_id = props.id;
  },
  beforeAdd:(params) => {
    params.driver_id = props.id;
    console.log(params)
    return true
  },
})

const columns = reactive([
  {
    title: "ID",
    dataIndex: "id",
    formType: "input",
    addDisplay: false,
    editDisplay: false,
    hide: true,
    align:'center',
    commonRules: {
      required: true,
      message: "请输入ID"
    }
  },
  {
    title: "所属司机",
    dataIndex: "driver_id", 
    align:'center',
    formType: 'select',
    addDisplay: false,
    editDisplay: false,
    search: false,
    dict: {
        // 远程通用接口请求，新版代码生成都有一个 remote 接口
        remote: 'prediction/driver/remote',
        // 指定组件接收的props
        props: { label: 'driver_name', value: 'id' },
        // 开启分页
        openPage: false,
        // 远程请求配置项
        remoteOption: {
            // 按用户名排序 
            sort: { driver_name: 'desc' }, // 如果不指定排序方式，默认为正序排序
            // 设置查询的字段
            select: [ 'id', 'driver_name' ],
            // 设置数据过滤
            filter: {
            },
            // 关联模型
            relations: [
            ]
        }
    }
  },
  {
			title: "行驶证",
			dataIndex: "xingshizheng",
			formType: "upload",
      type: 'image',
      align:'center',
      multiple: false,
	},
  {
			title: "车架号",
			dataIndex: "chejiahao",
      align:'center',
			formType: "input",
	},
  {
    title: "车型",
    dataIndex: "car_type",
    align:'center',
    formType: "input",
    search: true,
    commonRules: {
      required: true,
      message: "请输入车型"
    }
  },
  {
    title: "车牌号",
    dataIndex: "car_no",
    formType: "input",
    align:'center',
    search: true,
    commonRules: {
      required: true,
      message: "请输入车牌号"
    }
  },
  // {
  //   title: "是否默认",
  //   dataIndex: "is_default",
  //   align:'center',
  //   formType: "select",
  //   search: true,
  //   dict: {
  //     data: [
  //       {
  //         label: "否",
  //         value: "0"
  //       },
  //       {
  //         label: "是",
  //         value: "1"
  //       }
  //     ],
  //     translation: true
  //   }
  // },
  {
    title: "创建时间",
    dataIndex: "created_at",
    formType: "date",
    align:'center',
    search: true,
    addDisplay: false,
    editDisplay: false,
    showTime: true,
    hide: true,
  }
])
</script>
<script> export default { name: 'prediction:driverCar' } </script>